package com.huluwa.jczq;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

/**
 * Created by hancc on 2018/6/18.
 */
public class XMLParse {
    //日志投注信息解析成hashMap
    public static HashMap<String,String> getBetInfo(String xmlBetInfo) throws MalformedURLException {
        //得到请求URL信息
        URL url = new URL(xmlBetInfo);
        //得到请求参数
        String paramAll = url.getQuery();
        System.out.println(paramAll);
        String[] params = paramAll.split("&");
        String param = "";
        for(int i = 0;i<params.length;i++){
            if(params[i].contains("wParam")){
                param = params[i].substring(params[i].indexOf("=")+1);
            }
        }
        System.out.println(param);
        //拆分转化成hashMap
        String[] betInfo = param.split("_");
        HashMap<String,String> betInfoMap = new HashMap<String, String>();
        for(int i = 0;i<betInfo.length;i++){
            String key = betInfo[i].split("=")[0];
            String value = betInfo[i].split("=")[1];
            betInfoMap.put(key,value);
        }
        System.out.print(betInfoMap);
        return betInfoMap;

    }
    //日志重发报文解析成hashMap
    /*
  过关样例：
	<Project id="50250332">
<bill id="20316865196698129411" billtime="2011-05-04 14:56:24" issue="20110504" playid="SPF" maxbonu="78.47" ispass="1" passway="3*1" multi="1">
<match id="110504014">3=2.350</match>
<match id="110504015">0=3.150</match>
<match id="110504016">0=5.300</match>
</bill>
	</project>
说明:该方案是胜平负过关 3*1玩法。

单关样例：
<Project id="50110082">
<bill id="20127771336214604875" billtime="2011-05-03 16:05:14" issue="20110503" playid="SPF" maxbonu="0" ispass="0" passway="*" multi="1">
<match id="110504004">3=*|1=*|0=*</match>
</bill>
</Project>
说明：该方案是胜平负单关玩法。只选择了 一场比赛，包含该场比赛的所有可能性结果。
自由过关样例：
	<Project id="50250332">
<bill id="20316865196698129411" billtime="2017-06-15 14:56:24" issue="20110504" playid="SPF" maxbonu="78.47" ispass="1" passway="N3*2/3" multi="1">
<match id="170615014">3=2.350</match>
<match id="170615015">0=3.150</match>
<match id="170615016">0=5.300</match>
</bill>
	</project>
说明:该方案是胜平负自由过关选择3场比赛，过2关和3关玩法。其中这里的passway与投注串中的过关玩法一致

     */
    public static void getRnederInfo(String xmlRenderInfo){
        Document doc = Jsoup.parse(xmlRenderInfo);
        String projectId = doc.select("Project").attr("id");
        String bill = doc.select("bill[id*=\"20127771336214604875\"]").html();
        String billId = doc.select("bill[id*=\"20127771336214604875\"]").html();


        //String billId = doc.select("bill").attr("id");
        String billtime = doc.select("bill").attr("billtime");
        String issue = doc.select("bill").attr("issue");
        String playid = doc.select("bill").attr("playid");
        String maxbonu = doc.select("bill").attr("maxbonu");
        String ispass = doc.select("bill").attr("ispass");
        String passway = doc.select("bill").attr("passway");
        String multi = doc.select("bill").attr("mlti");
        System.out.print(bill);
        return ;
    }
    public static void main(String argv[]) throws MalformedURLException {
        // getBetInfo("http://www.baidu.com/hello?wAgent=3821&wAction=101&wMsgID=1194065967&wSign=6d8ce6c8cb4c76d60af98a87c8a9d723&wParam=OrderID=2007129298_LotID=10202_LotIssue=2007110818_LotMoney=12_LotMulti=2_OneMoney=2_LotCode=1|68,2,9;6|5,1,8_Attach=投注测试");
        getRnederInfo("<Project id=\"50110082\">\n" +
                "<bill id=\"20127771336214604875\" billtime=\"2011-05-03 16:05:14\" issue=\"20110503\" playid=\"SPF\" maxbonu=\"0\" ispass=\"0\" passway=\"*\" multi=\"1\">\n" +
                "<match id=\"110504004\">3=*|1=*|0=*</match>\n" +
                "</bill>\n" +
                "</Project>");
    }
}
